'use strict';
const { Controller } = require('egg');
const fs = require('fs-extra');
const p = require('path');

class FileController extends Controller {
  async uploadPic() {
    const { ctx } = this;
    const file = ctx.request.files[0];
    let query = ctx.query;
    let { word, id, type } = query;
    let filename = word + p.extname(file.filename);
    await this.service.file.savePic(file, { filename, word, type });
    ctx.success({data: { filename }, msg: '文件保存成功~'});
  }
}

module.exports = FileController;
